<script type="text/html" template lay-done="layui.data.setTimeDone(d)">
    <div class="layui-fluid custom-setTime-page">
        <form action="GET" class="layui-form" lay-filter="settime-form-filter">
            <div class="layui-form-item">
                <label class="layui-form-label time-descipt">任务填报时间：</label>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开始时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="starttime" id="myStartInput" lay-verify="required" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结束时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="endtime" id="myendInput" lay-verify="required" class="layui-input" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label eachtime-descipt">各单位填报时间设置：</label>
            </div>
            <div class="layui-form-item">
                <table id="timeTable" lay-filter="custom-fillTime-table"></table>
            </div>
            <div style="text-align: center;">
                <button type="button" lay-submit class="layui-btn" lay-filter="filltime-submit-filter">确认</button>
            </div>
            <textarea class="layui-textarea layui-hide"></textarea>
        </form>
    </div>
</script>

<style>
    .custom-setTime-page .layui-form-label{
        padding: 9px 10px 9px 0;
    }
    .time-descipt{
        width: 110px;
    }
    .eachtime-descipt{
        width: 150px;
    }
</style>

<!-- 日期时间模板 -->
<script type="text/html" id="datetime">
    <input type="text" name="approvalTime" class="layui-input layui-input-date">
</script>

<script>
    layui.data.setTimeDone = function (d) {
        layui.use(['admin', 'table', 'form', 'laydate'], function(){
            var admin = layui.admin,
                table = layui.table,
                form = layui.form,
                laydate = layui.laydate;
            
            var taskid = d.params.taskid ? d.params.taskid : '',
                allData;

            form.render();
            getTaskData(taskid);

            //获取任务信息
            function getTaskData(taskid){
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/IndexGetFillTime',
                    data: {
                        taskid: taskid
                    },
                    done: function(res){
                        var result = res.data;
                        $('.custom-setTime-page textarea').val(JSON.stringify(result.data));
                        if(result.retcode == 0){
                            var starttime = result.data.starttime.substring(0, 10),
                                endtime = result.data.endtime.substring(0, 10);
                            initLayDate(starttime, endtime);
                            table.render({
                                elem: '#timeTable',
                                height: 200,
                                even: true,
                                skin: 'nob',
                                text: {
                                    none: '<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
                                },
                                limit: 10000,
                                data: result.data.deptTimeList,
                                cols: [[
                                    { field: 'dept_name', title: '单位名称', align: 'center', event: ['nonull', 'varchar'] },
                                    { field: 'starttime', title: '开始时间', align: 'center', edit: 'text',event: ['nonull', 'date'] },
                                    { field: 'endtime', title: '结束时间', align: 'center', edit: 'text', event: ['nonull', 'date'] },
                                ]],
                                done: function(res, curr, count){
                                    if(res.data && res.count > 0){
                                        var startTds = $('[lay-id="timeTable"] td[data-field="starttime"] .layui-table-cell'),
                                            endTds = $('[lay-id="timeTable"] td[data-field="endtime"] .layui-table-cell');
                                        initTableLayDate(startTds);
                                        initTableLayDate(endTds);
                                    }
                                }   
                            })
                        }
                    }
                })
            }

            /*
            *初始化时间选择框 
            *@param starttime 开始时间
            *@param endtime 结束时间
            */
            function initLayDate(starttime, endtime){
                laydate.render({
                    elem: '#myStartInput',
                    value: starttime,
                    isInitValue: true
                });
                laydate.render({
                    elem: '#myendInput',
                    value: endtime,
                    isInitValue: true
                });
            }

            function initTableLayDate(tds){
                $.each(tds, function(index, item){
                    laydate.render({
                        elem: this,
                        trigger: 'click'
                    })
                })
            }

        })
    }
</script>